<?php
namespace app\home\controller;
use think\Db;
use think\captcha\Captcha;
use think\Loader;
class Dier extends \think\Controller{
    public function dier(){
        $reslist=db('topic')->select();
        $this->assign('reslist',$reslist);
        return $this->fetch('dier');//继承基类的控制器 
    }
    public function addConcern(){
        if(session('id')==NULL){
            $this->error('请先登录','',0);
        }
        $data['topic_id']=input('param.topic_id','','htmlspecialchars');
        $data['user_id']=session('id');
        $ret=db('guanzhu')->where('topic_id',$data['topic_id'])->where('user_id',$data['user_id'])->select();
        if($ret==NULL){
            $data['user_id']=session('id');
            $data['status']=1;
            $ret=db('guanzhu')->insertGetId($data);
            if($ret>0){
                $this->success('关注成功','',3);
            }
        }else{
            $ret=db('guanzhu')->where('topic_id',$data['topic_id'])->where('user_id',$data['user_id'])->delete();
            if($ret>0){
                $this->success('取消成功','',4);
            }
        }
        // dump($ret);
    }
}